package cn.wzy.controller;

import cn.wzy.annotation.AnPermission;
import cn.wzy.dto.RoleMenuDTO;
import cn.wzy.dto.RolePermissionDTO;
import cn.wzy.pojo.Role;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.RoleService;
import cn.wzy.vo.GoPageVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Role)表控制层
 *
 * @author makejava
 * @since 2022-12-08 13:53:10
 */
@RestController
@RequestMapping("/Role")
@AnPermission(name = "角色操作")
public class RoleController {
    /**
     * 服务对象
     */
    @Resource
    private RoleService roleService;


    /*
    * 角色分页
    * */
    @PostMapping("/page")
    @ApiOperation(value = "角色分页")
    @AnPermission(name = "角色分页高级查询")
    public ResponseResult rolePage(@RequestBody GoPageVo goPageVo){
        return roleService.rolePage(goPageVo);
    }

    /*
    * 删除角色
    * */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除单个角色")
    @AnPermission(name = "删除单个角色")
    public ResponseResult deleteRole(@PathVariable("id") Long id){
        return roleService.deleteRole(id);
    }

    /*
    * 保存角色
    * */
    @PostMapping
    @ApiOperation(value = "保存角色")
    @AnPermission(name = "保存角色")
    public ResponseResult saveRole(@RequestBody Role role){
        return roleService.saveRole(role);
    }

    /*
    * 修改角色权限
    * */
    @PostMapping("/permission")
    @ApiOperation(value = "修改角色权限")
    @AnPermission(name = "修改角色权限")
    public ResponseResult saveRolePermission(@RequestBody RolePermissionDTO rolePermissionDto){
        return roleService.saveRolePermission(rolePermissionDto);
    }

    /*
    * 修改 角色菜单
    * */
    @PostMapping("/menu")
    @ApiOperation(value = "修改角色菜单")
    @AnPermission(name = "修改角色菜单")
    public ResponseResult saveRoleMenu(@RequestBody RoleMenuDTO roleMenuDto){
        return roleService.saveRoleMenu(roleMenuDto);
    }


    /*
    * 获取所有角色
    * */
    @GetMapping("/all")
    @AnPermission(name = "获取所有角色")
    @ApiOperation(value = "获取所有角色")
    public ResponseResult getAllRole(){
        return roleService.getAllRole();
    }
}

